# Maintainer: Yuui Tanabe <yuuitanabe@163.com>

_realname=pinentry
pkgbase=mingw-w64-${_realname}
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname})
pkgver=1.1.1
pkgrel=1
url="https://www.gnupg.org/software/pinentry/index.html"
license=('GPL')
pkgdesc='Collection of simple PIN or passphrase entry dialogs which utilize the Assuan protocol (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
depends=("${MINGW_PACKAGE_PREFIX}-qt5-base"
         "${MINGW_PACKAGE_PREFIX}-libsecret"
         "${MINGW_PACKAGE_PREFIX}-libassuan")
source=("https://www.gnupg.org/ftp/gcrypt/pinentry/pinentry-${pkgver}.tar.bz2"{,.sig}
        "0001-m4-remove-rpath.patch")
sha256sums=('cd12a064013ed18e2ee8475e669b9f58db1b225a0144debdb85a68cecddba57f'
            'SKIP'
            '58a3e99e1d243cb867da5943a12b0e9174b2a154cc127f48b44d3bbc1f285a84')
validpgpkeys=('D8692123C4065DEA5E0F3AB5249B39D24F25E3B6' # Werner Koch (dist sig)
              '6DAA6E64A76D2840571B4902528897B826403ADA') # Werner Koch (dist signing 2020)

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-m4-remove-rpath.patch"

  # Empty VERSION file for clang
  echo > VERSION
  autoreconf -fiv
}

build()
{
  [[ -d ${srcdir}/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-pinentry-tty \
    --disable-pinentry-curses \
    --disable-fallback-curses \
    --disable-pinentry-emacs \
    --disable-pinentry-gtk2 \
    --disable-pinentry-gnome3 \
    --enable-pinentry-qt \
    --enable-libsecret

  make
}

package()
{
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR=${pkgdir} install
}
